package com.tico.common.utils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class StringUtil {
    public static String appendLikeStr(String str) {
        if (str != null) {
            return "%" + str + "%";
        }
        return null;
    }

    /**
     * 获取字符串str的separator 分割的  index下标的 字符串, 特殊规则判空
     * 判空规则 : NONE, NULL, Null, null, None, none, undefined, Undefined
     *
     * @param str
     * @param separator
     * @param index
     * @return
     */
    public static String getStringBySeparatorAndIndex(String str, String separator, int index) {
        if (str == null && index < 0) {
            return null;
        }

        String[] strs = str.split(separator);
        if (strs.length <= index) {
            return null;
        }

        String result = strs[index];

        if (result == null || result.trim().equals("NONE") || result.trim().equals("NULL")
                || result.trim().equals("Null") || result.trim().equals("null") || result.trim().equals("None")
                || result.trim().equals("none") || result.trim().equals("undefined")
                || result.trim().equals("Undefined")) {
            return null;
        }

        return result;
    }
}
